package com.wbl.network

data class BaseResponse<T>(
    val data: T,
    val errorCode: Int,
    val errorMsg: String?
)

fun <T> BaseResponse<T>.toResult(successCode: Int = 0): Result<T> {
    return if (this.errorCode == successCode && this.data != null) {
        Result.success(this.data)
    } else {
        Result.failure(Exception(this.errorMsg ?: "未知错误"))
    }
}
